﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RssToolkit.Web.WebControls;
using System.Configuration;

public partial class SiteWorx_UserControls_RssFeedLinks : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            LoadFeedLinks();
    }

    private void LoadFeedLinks()
    {
        RssHyperLink rssLink = null;
        if (ConfigurationManager.AppSettings["MakeAllRssFeedsAvailable"] != null &&
            ConfigurationManager.AppSettings["MakeAllRssFeedsAvailable"].ToString().Length > 0)
        {
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["MakeAllRssFeedsAvailable"].ToString()))
            {
                if (ConfigurationManager.AppSettings["RssFeedLinks"] != null && 
                    ConfigurationManager.AppSettings["RssFeedLinks"].ToString().Length > 0)
                {
                    char[] pipeSplitter = {'|'};
                    string[] feeds = ConfigurationManager.AppSettings["RssFeedLinks"].ToString().Split(pipeSplitter);
                    string[] feedDetails = null;
                    char[] commaSplitter = {','};

                    foreach(string feed in feeds)
                    {
                        feedDetails = feed.Split(commaSplitter);
                        rssLink = new RssHyperLink();
                        rssLink.Text = "";

                        if (ConfigurationManager.AppSettings[feedDetails[0].ToString()] != null &&
                            ConfigurationManager.AppSettings[feedDetails[0].ToString()].ToString().Length > 0)
                            rssLink.ChannelName = ConfigurationManager.AppSettings[feedDetails[0].ToString()].ToString();

                        rssLink.NavigateUrl = feedDetails[1].ToString();
                        Controls.Add(rssLink);
                    }
                }
            }
        }

    }
}
